package com.etc.cure.service.Impl;

import com.etc.common.utils.Result;
import com.etc.common.utils.UUIDUtil;
import com.etc.cure.R.ROutpatient;
import com.etc.cure.entity.Outpatient;
import com.etc.cure.mapper.OutpatientMapper;
import com.etc.cure.service.OutpatientService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OutpatientServiceImpl implements OutpatientService {

    @Resource
    private OutpatientMapper outpatientMapper;

    /**
     * 根据医生id查询门诊
     *
     * @param docId
     * @return
     */
    @Override
    public Result queryOutpatient(String docId) {
        List<ROutpatient> list = outpatientMapper.queryOutpatient(docId);
        return Result.ok(list);
    }

    /**
     * 新增门诊
     *
     * @param outpatient
     * @return
     */
    @Override
    public Result insertOutpatient(Outpatient outpatient) {
        outpatient.setOsId(UUIDUtil.getUUID());
        int result = outpatientMapper.insertOutpatient(outpatient);
        String message = result > 0 ? "新增成功！" : "新增失败！";
        return Result.ok(result, message);
    }

    /**
     * 根据门诊id修改门诊信息
     * @param outpatient
     * @return
     */
    @Override
    public Result updateOutpatient(Outpatient outpatient){
        int result = outpatientMapper.updateOutpatient(outpatient);
        String message = result > 0 ? "修改成功！" : "修改失败！";
        return Result.ok(result, message);
    }

    /**
     * 根据门诊id查询门诊
     * @param outPatientId
     * @return
     */
    @Override
    public Result queryOutpatientByOutpatientId(String outPatientId) {
        ROutpatient rOutpatient = outpatientMapper.queryOutpatientByOutpatientId(outPatientId);
        return Result.ok(rOutpatient);
    }

}
